
/**
 * @file
 * jQuery helper functions for the Vocabulary Access module's administration page.
 */

/**
 * Disable the coherent term section in the tables if no access granted to the vocabulary.
 */
Drupal.behaviors.disableTermSection = function (context) {
  var disableTermSection = function () {
    $("input:radio[class*='vocabulary']:checked").each(function () {
      if ($(this).val() == '0') {
        $(this).parents('tr').find("input:checkbox[class*='term']").attr('checked', false).attr("disabled", "disabled");
        $(this).parents('tr').find("input:radio[class*='term']").each(function() {
          $(this).attr("disabled", "disabled");
          if ($(this).val() == '0') {
            $(this).attr("checked", "checked");
          }
        });
      } else {
        $(this).parents('tr').find("input:checkbox[class*='term']").removeAttr("disabled");
        $(this).parents('tr').find("input:radio[class*='term']").each(function() {
          $(this).removeAttr("disabled");
        });
      }
    });
  }
  
  // Run at page load and vocabulary permission changes.
  $(function() { disableTermSection(); });
  $("input:radio[class*='vocabulary']").change(function(){ disableTermSection(); });
}